﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Global.Class.Library;

namespace DataTransferObject
{
    public class MarketingPaymentDetail : NotifyPropertyChangeObject
    {

        private int marketingIncentiveID;
        private int marketingIncentiveSerialID;
        private DateTime requestedDate;
        private string paymentPeriod;

        private int customerID;
        private string customerCode;
        private string customerName;


        private int marketingPaymentTermID;

        private double turnOverAmount;
        private double incentiveAmount;
        private double remainsAmount;
        private double paymentAmount;


        private string description;
        private string remarks;


        public MarketingPaymentDetail()
            : this(0, 0, DateTime.Today, "", 0, "", "", 0, 0, 0, 0, 0, "", "")
        {
        }

        public MarketingPaymentDetail(int marketingIncentiveID, int marketingIncentiveSerialID, DateTime requestedDate, string paymentPeriod, int customerID, string customerCode, string customerName, int marketingPaymentTermID, double turnOverAmount, double incentiveAmount, double remainsAmount, double paidAmount, string description, string remarks)
        {
            //GlobalDefaultValue.Apply(this);
            this.StopTracking();

            this.MarketingIncentiveID = marketingIncentiveID;
            this.MarketingIncentiveSerialID = marketingIncentiveSerialID;
            this.RequestedDate = requestedDate;
            this.PaymentPeriod = paymentPeriod;

            this.CustomerID = customerID;
            this.CustomerCode = customerCode;
            this.CustomerName = customerName;

            this.MarketingPaymentTermID = marketingPaymentTermID;

            this.TurnOverAmount = turnOverAmount;
            this.IncentiveAmount = incentiveAmount;
            this.RemainsAmount = remainsAmount;
            this.PaymentAmount = paidAmount;


            this.Description = description;
            this.Remarks = remarks;

            this.StartTracking();
        }


        #region Properties

        [DefaultValue(0)]
        public int CustomerID
        {
            get { return this.customerID; }
            set { ApplyPropertyChange<MarketingPaymentDetail, int>(ref this.customerID, o => o.CustomerID, value); }
        }

        [DefaultValue("")]
        public string CustomerCode
        {
            get { return this.customerCode; }
            set { ApplyPropertyChange<MarketingPaymentDetail, string>(ref this.customerCode, o => o.CustomerCode, value); }
        }

        [DefaultValue("")]
        public string CustomerName
        {
            get { return this.customerName; }
            set { ApplyPropertyChange<MarketingPaymentDetail, string>(ref this.customerName, o => o.CustomerName, value); }
        }






        [DefaultValue(0)]
        public int MarketingIncentiveID
        {
            get { return this.marketingIncentiveID; }
            set { ApplyPropertyChange<MarketingPaymentDetail, int>(ref this.marketingIncentiveID, o => o.MarketingIncentiveID, value); }
        }

        [DefaultValue(0)]
        public int MarketingIncentiveSerialID
        {
            get { return this.marketingIncentiveSerialID; }
            set { ApplyPropertyChange<MarketingPaymentDetail, int>(ref this.marketingIncentiveSerialID, o => o.MarketingIncentiveSerialID, value); }
        }

        [DefaultValue(typeof(DateTime), "01/01/1900")]
        public DateTime RequestedDate
        {
            get { return this.requestedDate; }
            set { ApplyPropertyChange<MarketingPaymentDetail, DateTime>(ref this.requestedDate, o => o.RequestedDate, value); }
        }


        [DefaultValue("")]
        public string PaymentPeriod
        {
            get { return this.paymentPeriod; }
            set { ApplyPropertyChange<MarketingPaymentDetail, string>(ref this.paymentPeriod, o => o.PaymentPeriod, value); }
        }


        [DefaultValue(0)]
        public int MarketingPaymentTermID
        {
            get { return this.marketingPaymentTermID; }
            set { ApplyPropertyChange<MarketingPaymentDetail, int>(ref this.marketingPaymentTermID, o => o.MarketingPaymentTermID, value); }
        }


        [DefaultValue(0)]
        public double TurnOverAmount
        {
            get { return this.turnOverAmount; }
            set { ApplyPropertyChange<MarketingPaymentDetail, double>(ref this.turnOverAmount, o => o.TurnOverAmount, value); }
        }

        [DefaultValue(0)]
        public double IncentiveAmount
        {
            get { return this.incentiveAmount; }
            set { ApplyPropertyChange<MarketingPaymentDetail, double>(ref this.incentiveAmount, o => o.IncentiveAmount, value); }
        }

        [DefaultValue(0)]
        public double RemainsAmount
        {
            get { return this.remainsAmount; }
            set { ApplyPropertyChange<MarketingPaymentDetail, double>(ref this.remainsAmount, o => o.RemainsAmount, value); }
        }


        [DefaultValue(0)]
        public double PaymentAmount
        {
            get { return this.paymentAmount; }
            set { ApplyPropertyChange<MarketingPaymentDetail, double>(ref this.paymentAmount, o => o.PaymentAmount, Math.Round(value, GlobalVariables.Round0Amount)); }
        }

        [DefaultValue("")]
        public string Description
        {
            get { return this.description; }
            set { ApplyPropertyChange<MarketingPaymentDetail, string>(ref this.description, o => o.Description, value); }
        }



        [DefaultValue("")]
        public string Remarks
        {
            get { return this.remarks; }
            set { ApplyPropertyChange<MarketingPaymentDetail, string>(ref this.remarks, o => o.Remarks, value); }
        }

        #endregion


        protected override System.Collections.Generic.List<ValidationRule> CreateRules()
        {
            List<ValidationRule> validationRules = base.CreateRules();
            validationRules.Add(new SimpleValidationRule("PaymentAmount", "Over payable amount.", delegate { return this.PaymentAmount <= this.RemainsAmount; }));

            return validationRules;
        }

    }
}
